<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%
   hide_entry ||= false
   entry_context ||= entry ? entry.context : parent_entry.context
%>
<div id="<%= "entry_#{entry.id}" if entry %>" style="<%= hidden unless entry %>" class="communication_sub_message <%= 'toggled_communication_sub_message' if hide_entry %> <%= 'blank' unless entry %> can_be_marked_as_read <%= entry ? entry.read_state(@current_user) : 'read' %>" data-mark-read-url="<%= entry && context_url(entry_context, :api_v1_context_discussion_topic_discussion_entry_mark_read_url, entry.discussion_topic, entry)%>">
  <div class="header">
    <div class="header_title">
      <a title="<%= t :authors_name, "Author's name" %>" href="<%= context_url(entry_context, :context_user_url, entry ? entry.user_id : '') %>" class="user_name">
        <%= context_user_name(entry ? entry.context : nil, entry ? entry.user_id : nil) %>
      </a>
    </div>
    <div class="link_box">
      <a href="<%= context_url(entry_context, :context_discussion_entry_url, entry ? entry.id : "{{ id }}") %>" class="delete_entry_link disabled_link"><%= image_tag "delete.png", :alt => t('Delete') %></a>
    </div>
    <div class="post_date time_ago_date" data-timestamp="<%= entry.try_rescue(:created_at).try_rescue(:iso8601) %>"><%= datetime_string(entry.try_rescue(:created_at)) || nbsp %></div>
    <div class="clear"></div>
  </div>
  <div class="content">
    <div style="float: left; margin: 0 5px 0 -10px;"><%= avatar(entry.try_rescue(:user_id), context_code: entry_context.asset_string, size: 30) %></div>
    <div class="course_id" style="display: none;"><%= entry_context.id if entry_context && entry_context.is_a?(Course) %></div>
    <div class="message user_content" style="<%= hidden unless entry %>"><%= user_content(entry.try_rescue(:message)) || nbsp %></div>
    <textarea class="message_html" style="display: none;"><%= h(entry.try_rescue(:message)) %></textarea>
    <% if !entry %>
     <%= form_for :discussion_entry, :url => context_url(entry_context, :context_discussion_entries_url), :html => {:class => "add_sub_message_form"} do |f| %>
        <%= f.hidden_field :discussion_topic_id, :value => parent_entry.discussion_topic_id %>
        <%= f.hidden_field :parent_id, :value => parent_entry.id, :class => "parent_id" %>
        <%= f.text_area :message, :style => "height: 200px;", :class => "rich_text" %>
        <div class="button-container" style="padding-bottom: 5px;">
          <button type="submit" class="btn btn-small submit_button"><%= t :post_message, "Post Message" %></button>
          <button type="button" class="btn button-secondary cancel_button"><%= t "#buttons.cancel", "Cancel" %></button>
        </div>
      <% end %>
    <% end %>
    <div class="clear"></div>
  </div>
  <div class="clear"></div>
</div>
